1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module shumate.DataSource;
26 
27 private import gio.AsyncResultIF;
28 private import gio.Cancellable;
29 private import glib.Bytes;
30 private import glib.ErrorG;
31 private import glib.GException;
32 private import gobject.ObjectG;
33 private import gobject.Signals;
34 private import shumate.c.functions;
35 public  import shumate.c.types;
36 private import std.algorithm;
37 
38 
39 /**
40  * The base class used to retrieve tiles as [struct@GLib.Bytes].
41  */
42 public class DataSource : ObjectG
43 {
44 	/** the main Gtk struct */
45 	protected ShumateDataSource* shumateDataSource;
46 
47 	/** Get the main Gtk struct */
48 	public ShumateDataSource* getDataSourceStruct(bool transferOwnership = false)
49 	{
50 		if (transferOwnership)
51 			ownedRef = false;
52 		return shumateDataSource;
53 	}
54 
55 	/** the main Gtk struct as a void* */
56 	protected override void* getStruct()
57 	{
58 		return cast(void*)shumateDataSource;
59 	}
60 
61 	/**
62 	 * Sets our main struct and passes it to the parent class.
63 	 */
64 	public this (ShumateDataSource* shumateDataSource, bool ownedRef = false)
65 	{
66 		this.shumateDataSource = shumateDataSource;
67 		super(cast(GObject*)shumateDataSource, ownedRef);
68 	}
69 
70 
71 	/** */
72 	public static GType getType()
73 	{
74 		return shumate_data_source_get_type();
75 	}
76 
77 	/**
78 	 * Gets the data for the tile at the given coordinates.
79 	 *
80 	 * Some data sources may return data multiple times. For example,
81 	 * [class@TileDownloader] may return data from a cache, then return updated
82 	 * data from the network. [signal@ShumateDataSource::received-data] is emitted
83 	 * each time data is received, then @callback is called after the last update.
84 	 *
85 	 * Params:
86 	 *     x = the X coordinate to fetch
87 	 *     y = the Y coordinate to fetch
88 	 *     zoomLevel = the Z coordinate to fetch
89 	 *     cancellable = a #GCancellable
90 	 *     callback = a #GAsyncReadyCallback to execute upon completion
91 	 *     userData = closure data for @callback
92 	 */
93 	public void getTileDataAsync(int x, int y, int zoomLevel, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
94 	{
95 		shumate_data_source_get_tile_data_async(shumateDataSource, x, y, zoomLevel, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
96 	}
97 
98 	/**
99 	 * Gets the final result of a request started with
100 	 * shumate_data_source_get_tile_data_async().
101 	 *
102 	 * Params:
103 	 *     result = a #GAsyncResult provided to callback
104 	 *
105 	 * Returns: The requested data, or %NULL if an
106 	 *     error occurred
107 	 *
108 	 * Throws: GException on failure.
109 	 */
110 	public Bytes getTileDataFinish(AsyncResultIF result)
111 	{
112 		GError* err = null;
113 
114 		auto __p = shumate_data_source_get_tile_data_finish(shumateDataSource, (result is null) ? null : result.getAsyncResultStruct(), &err);
115 
116 		if (err !is null)
117 		{
118 			throw new GException( new ErrorG(err) );
119 		}
120 
121 		if(__p is null)
122 		{
123 			return null;
124 		}
125 
126 		return new Bytes(cast(GBytes*) __p, true);
127 	}
128 
129 	/**
130 	 * Emitted when data is received for any tile. This includes any intermediate
131 	 * steps, such as data from the file cache, as well as the final result.
132 	 *
133 	 * Params:
134 	 *     x = the X coordinate of the tile
135 	 *     y = the Y coordinate of the tile
136 	 *     zoomLevel = the zoom level of the tile
137 	 *     bytes = the received data
138 	 */
139 	gulong addOnReceivedData(void delegate(int, int, int, Bytes, DataSource) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
140 	{
141 		return Signals.connect(this, "received-data", dlg, connectFlags ^ ConnectFlags.SWAPPED);
142 	}
143 }